package com.bridgeintelligent.tag.customer.controller;

import com.bridgeintelligent.tag.customer.entity.Result;
import com.bridgeintelligent.tag.customer.service.IThemeService;
import com.bridgeintelligent.tag.customer.theme.ThemeEnum;
import com.bridgeintelligent.tag.customer.theme.ThemeRelation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@Api(tags = "用户主题标签关系管理")
@AllArgsConstructor
@RestController
@RequestMapping("/api/theme")
@Slf4j
public class ThemeController {

    private IThemeService themeService;

    @ApiOperation("新增用户主题标签关系")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "theme", value = "关系信息")
    })
    @PostMapping("/add")
    public Result addTheme(@RequestBody ThemeRelation theme) {
        try {
            themeService.addTheme(theme);
            return new Result(0,"保存成功");
        } catch (Exception e) {
            log.error("新增用户主题标签关系：{}::"+e);
            return new Result(-1,"新增失败");
        }
    }


    @ApiOperation("修改用户主题标签关系")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "body", name = "theme", value = "关系信息")
    })
    @PostMapping("/update")
    public Result updateTheme(@RequestBody ThemeRelation theme) {
        try {
            themeService.updateTheme(theme);
            return new Result(0,"修改成功");
        } catch (Exception e) {
            log.error("修改用户主题标签关系：{}::"+e);
            return new Result(-1, "修改失败");
        }
    }

    @ApiOperation("删除用户主题标签关系")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "关系ID")})
    @GetMapping("/delete")
    public Result deleteTheme(String id) {
        try {
            themeService.deleteTheme(id);
            return new Result(0,"删除成功");
        }catch (Exception e){
            log.error("删除用户主题标签关系：{}::"+e);
            return new Result(-1,"删除失败");
        }

    }

    @ApiOperation("用户主题标签关系详情")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "关系ID")
    })
    @GetMapping("/findThemeRelation")
    public Result findThemeRelation(String id) {
        try {
            ThemeRelation themeRelation = themeService.findThemeRelation(id);
            return new Result(0,"查询成功",themeRelation);
        }catch (Exception e){
            log.error("查看用户主题标签关系失败：{}::"+e);
            return new Result(-1,"查看用户主题标签关系失败"+e.getMessage());
        }
    }

    @ApiOperation("主题信息列表")
    @ApiImplicitParams({})
    @GetMapping("/themeList")
    public Result themeList() {
        try {
            ThemeEnum[] values = ThemeEnum.values();
            HashMap map = new HashMap();
            for (ThemeEnum value : values) {
                map.put(value.getCode(),value.getName());
            }
            return new Result(0,"查询成功",map);
        }catch (Exception e){
            log.error("查看主题信息列表失败：{}::"+e);
            return new Result(-1,"查看主题信息列表失败"+e.getMessage());
        }
    }
}